<?php
    require_once "./common.php";
?>
<body>
<form class="layui-form">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body" pad15="" >
                        <div class="layui-form" lay-filter="" >
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <h2>留言板注册</h2>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">登录名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" value="" lay-verify="nickname"  autocomplete="off" placeholder="请输入登录名" class="layui-input name">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">昵称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="nickname" value="" lay-verify="nickname"  autocomplete="off" placeholder="请输入昵称" class="layui-input nickname">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" name="password" value=""  lay-verify="password" placeholder="请输入密码" autocomplete="off" class="layui-input password">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">确认密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" name="repassword" value=""  lay-verify="password" placeholder="请再次输入密码" autocomplete="off" class="layui-input repassword">
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">个人简介</label>
                                <div class="layui-input-block">
                                    <textarea name="info" placeholder="请输入个人简介" class="layui-textarea info" style="width: 300px"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="register">确认注册</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
</body>
</html>
<script>
    layui.use(["form","layer"],function () {
        var form = layui.form
        ,layer = layui.layer;

        form.on('submit(register)',function (data) {
            //发送ajax
            $.ajax({
                url : "./demo.php",
                type : "post",
                data : {
                    option     : "register",
                    name       : data.field.name,
                    nickname   : data.field.nickname,
                    password   : data.field.password,
                    repassword : data.field.repassword,
                    info       : data.field.info
                },
                dataType: "json",
                success : function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 50000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        parent.location.href = "./login.php";
                    }else {
                        layer.msg(res.msg, {
                            icon: 2,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                    }
                }
            });
        });

    });





</script>